package com.xbongbong.saas.help;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xbongbong.paas.constant.MessageConstant;
import com.xbongbong.paas.constant.PaasConstant;
import com.xbongbong.paas.domain.entity.PaasFormDataEntity;
import com.xbongbong.paas.domain.entity.PaasFormExplainEntity;
import com.xbongbong.paas.domain.entity.ext.PaasFormDataEntityExt;
import com.xbongbong.paas.elasticsearch.util.EsHelper;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.paas.enums.IndexTypeEnum;
import com.xbongbong.paas.field.DefaultAttrPoJo;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.field.FieldAttrEntityExt;
import com.xbongbong.paas.field.LinkInfoPojo;
import com.xbongbong.paas.field.LinkedAttrPoJo;
import com.xbongbong.paas.field.MultiUnitItemPoJo;
import com.xbongbong.paas.field.SaasParticularAttributePoJo;
import com.xbongbong.paas.field.SubFormPoJo;
import com.xbongbong.paas.field.UnitItemPoJo;
import com.xbongbong.paas.help.FormDataHelp;
import com.xbongbong.paas.model.PaasFormExplainModel;
import com.xbongbong.paas.pojo.MultiUnitPricePoJo;
import com.xbongbong.paas.pojo.ProductFieldPojo;
import com.xbongbong.paas.redis.RedisPrefixConstant;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.Arith;
import com.xbongbong.paas.toolbox.util.CloneUtil;
import com.xbongbong.paas.toolbox.util.StringUtil;
import com.xbongbong.paas.toolbox.wrap.UserVO;
import com.xbongbong.paas.util.ExplainUtil;
import com.xbongbong.pro.constant.BusinessConstant;
import com.xbongbong.pro.enums.errorcodes.SystemErrorCodeEnum;
import com.xbongbong.pro.formexplain.pojo.dto.HandlerExplainDTO;
import com.xbongbong.saas.constant.BasicConstant;
import com.xbongbong.saas.constant.MultiUnitConstant;
import com.xbongbong.saas.constant.ProductConstant;
import com.xbongbong.saas.constant.StockConstant;
import com.xbongbong.saas.constant.StringConstant;
import com.xbongbong.saas.enums.RelativeProductEnum;
import com.xbongbong.saas.enums.SelectProductEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.ProductEnum;
import com.xbongbong.saas.enums.product.PurchaseProductEnum;
import com.xbongbong.saas.model.ProductUnitPriceModel;
import com.xbongbong.saas.service.toolbox.help.AttrDecimalPrecisionHelper;
import com.xbongbong.saas.toolbox.help.FastJsonHelper;
import lombok.extern.slf4j.Slf4j;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

import static com.xbongbong.saas.toolbox.help.FastJsonHelper.getIntegerOrDefaultFromFormData;
import static org.elasticsearch.index.query.QueryBuilders.boolQuery;
import static org.elasticsearch.index.query.QueryBuilders.termQuery;
import static org.elasticsearch.index.query.QueryBuilders.termsQuery;

/**
 * @author 吴峰
 * @date 2023/04/11 9:46
 */
@Component
@Slf4j
public class ValidateLinkProductHelp {

    @Resource
    private EsHelper esHelper;
    @Resource
    private FormDataHelp formDataHelp;
    @Resource
    private PaasFormExplainModel paasFormExplainModel;
    @Resource
    private ProductUnitPriceModel productUnitPriceModel;
    @Resource
    private RelativeProductHelp relativeProductHelp;
    @Resource
    private SaasFormHelp saasFormHelp;
    @Resource
    private AttrDecimalPrecisionHelper attrDecimalPrecisionHelper;

    /**
     * 关联新建产品转换
     * @param contractDataList 源数据data,源数据产品
     * @param linkProductField 目标产品表单
     * @param attr 目标产品attr
     * @param linkAttr 源产品attr
     * @param corpid 公司id
     * @param loginUser
     * @param businessType
     * @param linkBusinessType
     * @return 新产品
     * @throws XbbException
     */
    public JSONArray otherProductToAnother(JSONObject contractDataList, FieldAttrEntity linkProductField, String attr, String linkAttr, String corpid, UserVO loginUser, Integer businessType, Integer linkBusinessType) throws XbbException {
        if (BasicConstant.ZERO.equals(linkProductField.getIsOpen())) {
            return new JSONArray();
        }
        if (Objects.isNull(linkProductField.getSubForm())){
            return new JSONArray();
        }
        JSONArray productArray = contractDataList.getJSONArray(linkAttr);
        Map<Long, PaasFormDataEntityExt> productMap = product2ShowMap(corpid,productArray);
        SubFormPoJo subFormPoJo = linkProductField.getSubForm();
        List<? extends FieldAttrEntity> items = subFormPoJo.getItems();
        List<String> linkAttrList = new ArrayList<>();
        List<String> productAttrList = new ArrayList<>();
        for(int i = 0;i < items.size();i++){
            FieldAttrEntity fieldAttrEntity = items.get(i);
            if (Objects.equals(fieldAttrEntity.getAttr(), SelectProductEnum.PRODUCT.getAttr())){
                LinkInfoPojo linkInfoPojo = fieldAttrEntity.getLinkInfo();
                List<LinkedAttrPoJo> linkedAttrPoJoList = linkInfoPojo.getLinkedAttr();
                List<LinkedAttrPoJo> linkedShowPojoList = linkInfoPojo.getLinkedShowAttr();
                linkedAttrPoJoList.forEach(linkedAttrPoJo -> linkAttrList.add(linkedAttrPoJo.getAttr()));
                linkedShowPojoList.forEach(linkedAttrPoJo -> linkAttrList.add(linkedAttrPoJo.getAttr()));
            }else {
                if (Objects.equals(fieldAttrEntity.getIsRedundant(),0)){
                    productAttrList.add(fieldAttrEntity.getAttr());
                }
            }
        }
        productAttrList.add(BusinessConstant.PRODUCT_SUB_ID);
        productAttrList.add(BusinessConstant.REF_PRODUCT_ID);
        productAttrList.add(BusinessConstant.RELY_PRODUCT_SUB_ID);
        productAttrList.add(MultiUnitConstant.RATE);
        if (Objects.equals(XbbRefTypeEnum.PURCHASE.getCode(),businessType) && (Objects.equals(XbbRefTypeEnum.CONTRACT.getCode(),linkBusinessType) || Objects.equals(XbbRefTypeEnum.PRODUCT.getCode(),linkBusinessType))){
            productAttrList.add("contractId");
            productAttrList.add("productId");
            productAttrList.add("contractProductId");
            productAttrList.add(PurchaseProductEnum.CONTRACT_NO.getAttr());
        }
        JSONArray newArray = new JSONArray();
        PaasFormExplainEntity explainEntity = paasFormExplainModel.getByBusinessType(XbbRefTypeEnum.PRODUCT.getCode(), corpid);
        if (Objects.isNull(explainEntity)) {
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, MessageConstant.FORM_EXPLAIN_NOT_EXIST);
        }
        Map<String, FieldAttrEntity> productExplainMap = ExplainUtil.getExplainMap(explainEntity.getExplains(), null);
        HandlerExplainDTO handlerExplainDTO = new HandlerExplainDTO();
        handlerExplainDTO.setLoginUser(loginUser);
        handlerExplainDTO.setUserId(loginUser.getUserId());
        Map<Long, List<MultiUnitPricePoJo>> priceMap = productUnitPriceModel.getPriceMapByProductIdSet(corpid, productMap.keySet());
        Map<Long, MultiUnitItemPoJo> groupBaseUnitMap = relativeProductHelp.getGroupBaseUnitMap(corpid);
        // 暂时不处理产品负责人
        for(int i = 0;i < productArray.size();i++) {
            JSONObject sellingMap = new JSONObject();
            JSONObject newSubform = new JSONObject();
            JSONObject json = productArray.getJSONObject(i);
            Long productId = json.getLong(SelectProductEnum.PRODUCT.getAttr());
            Long refProductId = json.getLong(BusinessConstant.REF_PRODUCT_ID);
            for (Map.Entry<String, Object> entry : json.entrySet()) {
                if (Objects.equals(entry.getKey(), SelectProductEnum.PRODUCT.getAttr())) {
                    JSONObject productData = new JSONObject();
                    PaasFormDataEntity productEntity = productMap.get(productId);
                    if (Objects.isNull(productEntity)) {
                        continue;
                    }
                    log.info("处理产品数据productId："+productId);
                    for (String str : linkAttrList) {
                        // 源单的批次 生产日期 保质期
                        if (Objects.equals(str,SelectProductEnum.SOURCE_BATCH.getAttr())){
                            if (json.get(SelectProductEnum.BATCH.getAttr()) != null && json.get(SelectProductEnum.BATCH.getAttr()) instanceof  JSONObject){
                                productData.put(str, json.get(SelectProductEnum.BATCH.getAttr()) != null && json.getJSONObject(SelectProductEnum.BATCH.getAttr()).getString("text") != null ? json.getJSONObject(SelectProductEnum.BATCH.getAttr()).getString("text") : null);
                            } else if (json.get(SelectProductEnum.BATCH.getAttr()) != null ){
                                productData.put(str, json.get(SelectProductEnum.BATCH.getAttr()) != null ? json.getString(SelectProductEnum.BATCH.getAttr()) : null);
                            }
                        }
                        if (Objects.equals(str,SelectProductEnum.SOURCE_PRICE.getAttr())){
                            productData.put(SelectProductEnum.PRICE.getAttr(),json.get(SelectProductEnum.PRICE.getAttr()));
                        }
                        if (Objects.equals(str,SelectProductEnum.SOURCE_PRODUCE_DATE.getAttr())){
                            productData.put(str, json.get(SelectProductEnum.PRODUCE_DATE.getAttr()) != null ? json.getIntValue(SelectProductEnum.PRODUCE_DATE.getAttr()) : null);
                        }
                        if (Objects.equals(str,SelectProductEnum.SOURCE_GUARANTEE_PERIOD.getAttr()) && Objects.nonNull(json.get(SelectProductEnum.PRODUCE_DATE.getAttr())) && json.getLong(SelectProductEnum.PRODUCE_DATE.getAttr()) > 0L){
                            productData.put(str, json.get(SelectProductEnum.GUARANTEE_PERIOD.getAttr()) != null ? json.getLongValue(SelectProductEnum.GUARANTEE_PERIOD.getAttr()) : null);
                        }
                        FieldAttrEntity fieldAttrEntity = productExplainMap.get(str);
                        if (Objects.isNull(fieldAttrEntity)) {
                            continue;
                        }
                        handlerExplainDTO.setCreatorId(productEntity.getCreatorId());
                        if (ExplainUtil.isFieldNeedHide(fieldAttrEntity, handlerExplainDTO)) {
                            continue;
                        }
                        if (Objects.equals(str, FieldTypeEnum.SERIALNO.getAlias())){
                            productData.put(str, productEntity.getSerialNo());
                        }else {
                            productData.put(str, productEntity.getData().get(str));
                        }
                    }
                    JSONObject linkDataJson = new JSONObject();
                    linkDataJson.put("data", productData);
                    linkDataJson.put("dataId", productEntity.getDataId());
                    // 前端需要
                    if (Objects.nonNull(refProductId)) {
                        linkDataJson.put("id", refProductId);
                    } else {
                        linkDataJson.put("id", productEntity.getDataId());
                    }
                    Integer enableMultiUnit = getIntegerOrDefaultFromFormData(productEntity.getData(), ProductEnum.ENABLE_MULTI_UNIT.getAttr(), 0);
                    Integer enableSerial = getIntegerOrDefaultFromFormData(productEntity.getData(), ProductEnum.ENABLE_SERIAL_NUMBER.getAttr(), 0);

                    if (Objects.equals(enableMultiUnit, 1)) {
                        MultiUnitItemPoJo multiUnitItemPoJo = groupBaseUnitMap.getOrDefault(productEntity.getData().getLong(ProductEnum.UNIT.getAttr()), new MultiUnitItemPoJo());
                        // 多单位产品
                        JSONObject unitObj = FastJsonHelper.getJsonObjectOrDefaultFromFormData(json, SelectProductEnum.UNIT.getAttr(), new JSONObject());
                        // 是多单位，但是是单单位的value，或没有值，补成基本单位
                        if (unitObj.isEmpty() || !StringUtil.isDigital(unitObj.getString(StringConstant.VALUE)) || unitObj.getLong(StringConstant.VALUE) < ProductConstant.MAX_SINGLE_UNIT_VALUE) {
                            unitObj.put(MultiUnitConstant.MULTI_UNIT_TEXT, multiUnitItemPoJo.getBaseName());
                            unitObj.put(MultiUnitConstant.VALUE, multiUnitItemPoJo.getBaseValue());
                            json.put(SelectProductEnum.UNIT.getAttr(), unitObj);
                        }
                        Long unitValue = unitObj.getLong(StringConstant.VALUE);
                        List<UnitItemPoJo> itemDataPoJoList = multiUnitItemPoJo.getItemDataPoJoList();
                        List<UnitItemPoJo> copyItemPojoList = (List<UnitItemPoJo>) CloneUtil.deepClone(itemDataPoJoList);
                        newSubform.put(ProductConstant.TRANSFORM_UNIT_RATE, itemDataPoJoList);
                        Map<Long, UnitItemPoJo> businessUnitMap = itemDataPoJoList.stream().collect(Collectors.toMap(UnitItemPoJo::getValue, data -> data));
                        if (!ProductConstant.NO_LINK_BUSINESS_TYPE_LIST.contains(businessType)) {
                            copyItemPojoList.removeIf(item -> !(Objects.equals(item.getValue(), unitValue) || Objects.equals(item.getIsBase(), 1)));
                        }
                        newSubform.put(ProductConstant.UNIT_RATE, copyItemPojoList);
                        boolean otherInOutStock = (Objects.equals(businessType, XbbRefTypeEnum.INSTOCK.getCode()) && (Objects.equals(linkBusinessType, XbbRefTypeEnum.INVENTORY.getCode()) || Objects.equals(linkBusinessType, XbbRefTypeEnum.TRANSFER.getCode())))
                                || (Objects.equals(businessType, XbbRefTypeEnum.OUTSTOCK.getCode()) && (Objects.equals(linkBusinessType, XbbRefTypeEnum.INVENTORY.getCode()) || Objects.equals(linkBusinessType, XbbRefTypeEnum.TRANSFER.getCode())));
                        if (StockConstant.MULTI_UNIT_TYPE_LIST.contains(businessType) && !(StockConstant.SERIAL_TYPE_LIST.contains(businessType) && Objects.equals(enableSerial, 1)) && !otherInOutStock) {
                            // 是多单位业务类型而且不是（既开启序列号且是序列号业务类型）
                            if (StockConstant.MULTI_UNIT_PRICE_TYPE_LIST.contains(businessType)) {
                                newSubform.put(ProductConstant.PRICE, priceMap.get(productId));
                            }
                            json.forEach((key,value)->{
                                if (ProductConstant.MULTI_PRICE_ATTR_LIST.contains(key)) {
                                    sellingMap.put(key, value);
                                }
                            });
                            newSubform.put(ProductConstant.SELLING_PRICE_MAP, sellingMap);
                            newSubform.put(ProductEnum.ENABLE_MULTI_UNIT.getSaasAttr(), 1);
                        } else {
                            // 不是多单位业务类型，或者是（序列号产品且是序列号业务类型）,此时不能选单位，只能是基本单位
                            if (!otherInOutStock) {
                                newSubform.put(SelectProductEnum.NUM.getAttr(), Arith.mul(json.getDouble(SelectProductEnum.NUM.getAttr()), businessUnitMap.getOrDefault(unitValue, new UnitItemPoJo()).getRate() == null ? 1D : businessUnitMap.getOrDefault(unitValue, new UnitItemPoJo()).getRate()));
                                unitObj.put(MultiUnitConstant.MULTI_UNIT_TEXT, multiUnitItemPoJo.getBaseName());
                                unitObj.put(MultiUnitConstant.VALUE, multiUnitItemPoJo.getBaseValue());
                                json.put(SelectProductEnum.UNIT.getAttr(), unitObj);
                            }
                            newSubform.put(ProductEnum.ENABLE_MULTI_UNIT.getSaasAttr(), 0);
                        }

                    } else {
                        // 单单位产品
                        newSubform.put(ProductEnum.ENABLE_MULTI_UNIT.getSaasAttr(), 0);
                        json.put(SelectProductEnum.UNIT.getAttr(), saasFormHelp.formatUnit(corpid, productEntity.getData().getString(ProductEnum.UNIT.getAttr())));
                    }
                    newSubform.put(SelectProductEnum.PRODUCT.getAttr(), linkDataJson);
                    newSubform.put(SelectProductEnum.STOCK.getAttr(),productEntity.getData().get(ProductEnum.STOCK.getAttr()));
                }
                if (Objects.equals(entry.getKey(), SelectProductEnum.DISCOUNT.getAttr())) {

                    DefaultAttrPoJo defaultAttr = linkProductField.getDefaultAttr();
                    String discountStr = "";
                    if (Objects.nonNull(defaultAttr)) {
                        discountStr = json.getString(SelectProductEnum.DISCOUNT.getAttr());
                    }
                    SaasParticularAttributePoJo saasParticularAttributePoJo = linkProductField.getSaasParticularAttributePoJo();
                    if (Objects.nonNull(saasParticularAttributePoJo) && Objects.nonNull(saasParticularAttributePoJo.getProductExplains())) {
                        List<FieldAttrEntityExt> productExplains = saasParticularAttributePoJo.getProductExplains();
                        for (FieldAttrEntityExt fieldAttrEntityExt : productExplains) {
                            if (Objects.equals(fieldAttrEntityExt.getAttr(), RelativeProductEnum.SALE_DISCOUNT.getSaasAttr())) {
                                Integer accuracy = fieldAttrEntityExt.getAccuracy();
                                Object zeroAccuracy = attrDecimalPrecisionHelper.setDecPrecision(Double.parseDouble(discountStr), accuracy);
                                json.put(SelectProductEnum.DISCOUNT.getAttr(), Double.parseDouble(zeroAccuracy.toString()));
                            }
                        }
                    }
                }
                if (productAttrList.contains(entry.getKey())) {
                    newSubform.put(entry.getKey(),entry.getValue());
                }
            }
            newArray.add(newSubform);
        }
        loyalToProduct(newArray,corpid,loginUser);
        return newArray;
    }

    private Map<Long,PaasFormDataEntityExt> product2ShowMap(String corpid, JSONArray productList) throws XbbException {
        if (productList.isEmpty()){
            return new HashMap<>();
        }
        List<Long> productIdLit = new ArrayList<>();
        for (int i = 0; i < productList.size(); i++){
            JSONObject jsonObject = productList.getJSONObject(i);
            if (Objects.nonNull(jsonObject.getLong(SelectProductEnum.PRODUCT.getAttr()))) {
                productIdLit.add(jsonObject.getLong(SelectProductEnum.PRODUCT.getAttr()));
            }
        }
        if (productIdLit.isEmpty()) {
            return new HashMap<>();
        }
        BoolQueryBuilder boolQueryBuilder = boolQuery();
        boolQueryBuilder.filter(termQuery("corpid.keyword",corpid));
        boolQueryBuilder.filter(termsQuery(FieldTypeEnum.DATAID.getAlias(),productIdLit));
//        boolQueryBuilder.filter(termQuery(StringConstant.DEL,DelEnum.NORMAL.getDel()));
        List<String> fieldList = Arrays.asList(FieldTypeEnum.DATAID.getAlias(),ProductEnum.getAttrConnectData(ProductEnum.NAME),ProductEnum.getAttrConnectData(ProductEnum.PRODUCT_NO),ProductEnum.getAttrConnectData(ProductEnum.BARCODE),ProductEnum.getAttrConnectData(ProductEnum.SPECIFICATION_LINK_TEXT),ProductEnum.getAttrConnectData(ProductEnum.UNIT),ProductEnum.getAttrConnectData(ProductEnum.COST),ProductEnum.getAttrConnectData(ProductEnum.PARENT_ID));
        List<PaasFormDataEntityExt> childList = esHelper.findByScroll(IndexTypeEnum.IDX_SAAS_PRODUCT,boolQueryBuilder,PaasFormDataEntityExt.class,null);
        Map<Long, PaasFormDataEntityExt> productMap = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        formDataHelp.setChildSpecification(childList,corpid);
        for (PaasFormDataEntityExt entityExt : childList) {
            JSONObject data = entityExt.getData();
            if (Objects.isNull(data.getString(ProductEnum.NAME.getAttr()))){
                data.put(ProductEnum.NAME.getAttr(),"");
            }
            if (Objects.isNull(entityExt.getSerialNo())){
                entityExt.setSerialNo("");
            }
            if (Objects.isNull(data.getString(ProductEnum.UNIT.getAttr()))){
                data.put(ProductEnum.UNIT.getAttr(),"");
            }
            if (Objects.isNull(data.getString(ProductEnum.BARCODE.getAttr()))){
                data.put(ProductEnum.BARCODE.getAttr(),"");
            }
            if (Objects.isNull(data.getDouble(ProductEnum.PRICE.getAttr()))){
                data.put(ProductEnum.PRICE.getAttr(),"");
            }
            if (Objects.isNull(data.getDouble(ProductEnum.COST.getAttr()))){
                data.put(ProductEnum.COST.getAttr(),"");
            }
            productMap.put(entityExt.getDataId(),entityExt);
        }
        return productMap;
    }

    /**
     * 关联产品部分字段跟随产品字段精度，可见性
     * @param productArray
     * @param corpid
     */
    public void loyalToProduct(JSONArray productArray, String corpid,UserVO loginUser) throws XbbException {
        ProductFieldPojo costField = saasFormHelp.getProductFieldPojo(RedisPrefixConstant.PRODUCT_COST,ProductEnum.COST.getAttr(), corpid);
        ProductFieldPojo priceField = saasFormHelp.getProductFieldPojo(RedisPrefixConstant.PRODUCT_PRICE,ProductEnum.PRICE.getAttr(), corpid);
        ProductFieldPojo stockField = saasFormHelp.getProductFieldPojo(RedisPrefixConstant.PRODUCT_STOCK,ProductEnum.STOCK.getAttr(), corpid);
        for (int i = 0;i < productArray.size();i++) {
            JSONObject jsonObject = productArray.getJSONObject(i);
            /**
             * 以下成本
             */
            if (jsonObject.containsKey(SelectProductEnum.COST.getAttr())){
                jsonObject.put(SelectProductEnum.COST.getAttr(),attrDecimalPrecisionHelper.setPrecision(jsonObject.getDouble(SelectProductEnum.COST.getAttr()),costField.getAccuracy()));
            }
            if (jsonObject.containsKey(SelectProductEnum.TOTAL_COST.getAttr())){
                jsonObject.put(SelectProductEnum.TOTAL_COST.getAttr(),attrDecimalPrecisionHelper.setPrecision(jsonObject.getDouble(SelectProductEnum.TOTAL_COST.getAttr()),costField.getAccuracy()));
            }
            /**
             * 以下单价
             */
            if (jsonObject.containsKey(SelectProductEnum.PRICE.getAttr())){
                jsonObject.put(SelectProductEnum.PRICE.getAttr(),attrDecimalPrecisionHelper.setPrecision(jsonObject.getDouble(SelectProductEnum.PRICE.getAttr()),priceField.getAccuracy()));
            }
            if (jsonObject.containsKey(SelectProductEnum.SELLING_PRICE.getAttr())){
                jsonObject.put(SelectProductEnum.SELLING_PRICE.getAttr(),attrDecimalPrecisionHelper.setPrecision(jsonObject.getDouble(SelectProductEnum.SELLING_PRICE.getAttr()),priceField.getAccuracy()));
            }
            if (jsonObject.containsKey(SelectProductEnum.SUBTOTAL.getAttr())){
                jsonObject.put(SelectProductEnum.SUBTOTAL.getAttr(),attrDecimalPrecisionHelper.setPrecision(jsonObject.getDouble(SelectProductEnum.SUBTOTAL.getAttr()),priceField.getAccuracy()));
            }
            /*以下库存*/
            if (jsonObject.containsKey(SelectProductEnum.STOCK.getAttr())){
                jsonObject.put(SelectProductEnum.STOCK.getAttr(),attrDecimalPrecisionHelper.setPrecision(jsonObject.getDouble(SelectProductEnum.STOCK.getAttr()),stockField.getAccuracy()));
            }
            if (jsonObject.containsKey(SelectProductEnum.NUM.getAttr())){
                jsonObject.put(SelectProductEnum.NUM.getAttr(),attrDecimalPrecisionHelper.setPrecision(jsonObject.getDouble(SelectProductEnum.NUM.getAttr()),stockField.getAccuracy()));
            }
        }
    }
}
